﻿using UnityEngine;
using System.Collections;

namespace DragonRescue3D
{
    /// <summary>
    /// Manages the rocket gameobject, slider and all associated child components
    /// </summary>
    public class RocketManager : MonoBehaviour
    {
        public Rocket Rocket;
        public Transform SliderOrigin;
        public Transform SliderEndPoint;
        public Texture2D ActiveCursor; 
        public int cursorSizeX = 50; 
        public int cursorSizeY = 50; 

        /// <summary>
        /// Temporarily deactivate the rocket on initialisation
        /// </summary>
        void Start()
        {
            Rocket.Deactivate();
        }

        /// <summary>
        /// Draw a line representing the slider the rocket is snapped to ( editor mode only )
        /// </summary>
        void OnDrawGizmos()
        {
            Gizmos.DrawLine(SliderOrigin.position, SliderEndPoint.position);
        }

        /// <summary>
        /// Manage the state of the rocket based on user mouse-clicks
        /// </summary>
        void OnGUI()
        {
            Event e = Event.current;

            if (Rocket != null)
            {
                // If the the user has double clicked and the rocket is ready fro take-off then fire it!
                if (e.type == EventType.MouseDown && e.clickCount == 2 && Rocket.IsActive)
                {
                    Rocket.Fire();
                }

                // If the rocket is ready for take-off then change the cursor to reflect its state
                if (Rocket.IsActive)
                {
                    Cursor.visible = false;
                    GUI.DrawTexture(new Rect(Event.current.mousePosition.x - cursorSizeX / 2, Event.current.mousePosition.y - cursorSizeY / 2, cursorSizeX, cursorSizeY), ActiveCursor);
                }
                else
                {
                    Cursor.visible = true;
                }
            }
        }
    }
}

#if NO_AND_ERROR
public void TEXT1() 
{
	int textNum = 1;
	if (textNum == 1) 
	{
		textNum = 2;
    }
}
public void TEXT2()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}
public void TEXT3()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT4()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT5()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT6()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT8()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT9()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT10()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT11()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT12()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT13()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT14()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT15()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT16()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}

public void TEXT17()
{
    int textNum = 1;
    if (textNum == 1)
    {
        textNum = 2;
    }
}
#endif